package com.originskyseed.platform.user.controller;

import java.util.Arrays;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.originskyseed.platform.core.aspect.annotation.RequiredParams;
import com.originskyseed.platform.core.base.BaseController;
import com.originskyseed.platform.core.base.BaseLocaleResource;
import com.originskyseed.platform.core.base.BasePage;
import com.originskyseed.platform.core.base.BaseResponseBody;
import com.originskyseed.platform.core.common.code.CommonResponseCode;
import com.originskyseed.platform.user.i18n.UserResponseMsg;
import com.originskyseed.platform.user.model.PlayerRelateLabelFile;
import com.originskyseed.platform.user.service.IPlayerRelateLabelFileService;
import com.originskyseed.platform.user.vo.request.PlayerRelateLabelFileRequestVO;

/**
 * 玩家标签附件信息表Controller类（OSI_PLAYER_RELATE_LABEL_FILE）
 *
 * @author wlj
 */
@Controller
@RequestMapping("/playerRelateLabelFile")
@BaseLocaleResource(localeFileName = "i18n_user")
public class PlayerRelateLabelFileController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(PlayerRelateLabelFileController.class);

	@DubboReference
	private IPlayerRelateLabelFileService playerRelateLabelFileService;

	/**
	 * 分页查询
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/playerRelateLabelFileList.json", method = RequestMethod.POST)
	@RequiredParams(names = { "pageNo", "pageSize" })
	public BaseResponseBody<BasePage<PlayerRelateLabelFile>> playerRelateLabelFileList(HttpServletRequest request) {
		BaseResponseBody<BasePage<PlayerRelateLabelFile>> result = null;
		try {
			// 请求对象
			PlayerRelateLabelFileRequestVO requestVO = this.getParameterBean(PlayerRelateLabelFileRequestVO.class);

			// 分页查询
			BasePage<PlayerRelateLabelFile> page = new BasePage<PlayerRelateLabelFile>(requestVO.getPageNo(), requestVO.getPageSize());
			page = this.playerRelateLabelFileService.selectListByPage(requestVO.toMap(), page);
			result = new BaseResponseBody<BasePage<PlayerRelateLabelFile>>(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), UserResponseMsg.DATA_LIST_SUCCESS.getMsg()), page);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody<BasePage<PlayerRelateLabelFile>>(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), UserResponseMsg.DATA_LIST_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 保存信息
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/playerRelateLabelFileSave.json", method = RequestMethod.POST)
	@RequiredParams(names = {})
	public BaseResponseBody<PlayerRelateLabelFile> playerRelateLabelFileSave(HttpServletRequest request) {
		BaseResponseBody<PlayerRelateLabelFile> result = null;
		try {
			// 请求对象
			PlayerRelateLabelFile playerRelateLabelFile = this.getParameterBean(PlayerRelateLabelFile.class);

			if (StringUtils.isNotBlank(playerRelateLabelFile.getId())) {
				this.playerRelateLabelFileService.updateByPrimaryKey(playerRelateLabelFile);
			} else {
				this.playerRelateLabelFileService.insertSelective(playerRelateLabelFile);
			}
			result = new BaseResponseBody<PlayerRelateLabelFile>(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), UserResponseMsg.DATA_SAVE_SUCCESS.getMsg()), playerRelateLabelFile);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody<PlayerRelateLabelFile>(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), UserResponseMsg.DATA_SAVE_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 删除信息
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/playerRelateLabelFileDelete.json", method = RequestMethod.POST)
	@RequiredParams(names = { "ids" })
	public BaseResponseBody<Boolean> playerRelateLabelFileDelete(HttpServletRequest request) {
		BaseResponseBody<Boolean> result = null;
		try {
			// 请求参数
			String[] ids = this.getParameterArray("ids", new String[] {});

			this.playerRelateLabelFileService.deleteByPrimaryKeys(Arrays.asList(ids));
			result = new BaseResponseBody<Boolean>(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), UserResponseMsg.DATA_DELETE_SUCCESS.getMsg()), true);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody<Boolean>(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), UserResponseMsg.DATA_DELETE_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

}
